package com.qf.service.impl;

import com.qf.bean.Grade2;
import com.qf.bean.Student2;
import com.qf.dao.Grade2Dao;
import com.qf.dao.Student2Dao;
import com.qf.service.Student2Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * IntelliJ IDEA -> springdata
 * 2019/12/2 15:40
 *
 * @author zmyao
 * 别看，我是渣渣。
 */
@Service("stuservice")
public class Student2ServiceImpl implements Student2Service {
    @Autowired
    private Student2Dao student2Dao;
    @Autowired
    private Grade2Dao grade2Dao;
    @Transactional
    @Override
    public int insert( Grade2 grade,Student2 student) {
        try {
            Grade2 grade1 = grade2Dao.save(grade);
            student.setGrade2(grade1);
            student2Dao.save(student);
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
        return 1;
    }

    @Override
    public Student2 findBySid(int sid) {
        return student2Dao.findOne(sid);
    }

    @Override
    public Grade2 findByGid(int gid) {
        return grade2Dao.findOne(gid);
    }

    @Override
    public List<Student2> findByGrade2_Gid(int gid) {
        return student2Dao.findByGrade2_Gid(gid);
    }

    @Override
    public Student2 findbyid(int sid) {
        return student2Dao.findbyid(sid);
    }

    @Override
    public Student2 findbyid_name(int sid, String sname) {
        return student2Dao.findbyid_name(sid,sname);
    }

    @Override
    public Student2 findbyid_name1(int sid, String suname) {
        return student2Dao.findbyid_name1(sid, suname);
    }

    @Override
    public List<Student2> getStudent2sBygid(int gid) {
        return student2Dao.getStudent2sBygid(gid);
    }

    @Override
    public List<Student2> getStudent2sBygid1(int sid ,String sname ) {
        return student2Dao.getStudent2sBygid1(sid ,sname );
    }
}
